import Vue from 'vue'
import App from './App.vue'
import router from './router/index'
import axios from 'axios'
import VueLazyload from 'vue-lazyload'
import VueAxios from 'vue-axios'
import { Message, FormItem, Form, Select, Option, Input } from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import VueCookie from 'vue-cookie'
import store from './store/index'
Vue.use(VueCookie)
Vue.use(VueLazyload, {
  loading: '/imgs/loading-svg/loading-bars.svg'
})

Vue.use(VueAxios, axios)
Vue.use(FormItem).use(Form).use(Input).use(Select).use(Option)
Vue.prototype.$message = Message;
axios.defaults.baseURL = '/api';//基准路径
axios.defaults.timeout = 8000
//错误拦截
axios.interceptors.response.use(response => {
  let res = response.data
  let path = location.hash
  if (res.status == 0) {
    return res.data
  } else if (res.status == 10) {
    //  window.location.href = '/#/login'//不能直接用this.$router.push('/login')
    if (path != '#/index') {
      router.push('/login')
      return Promise.reject(res)
    }

  } else {
    Message.warning(res.msg);
    return Promise.reject(res)
  }
}, error => {
  Message.error(error.response.data.message)
  return Promise.reject(error);//这一步解决不要进入then()的操作
})
Vue.config.productionTip = false
new Vue({
  store,
  router,
  render: h => h(App),
}).$mount('#app')
